import * as API from "../../../api/index"
import { defineStore } from "pinia"
import { ref } from "vue"

const { musicHallApi } = API.default
export const useMusicHallStore = defineStore('musicHallStore', () => {
    const highQualityList = ref([] as any[])
    const newSongs = ref([] as any[])
    const hotDjLIst = ref([] as any[])
    const newAlbum = ref([] as any[])
    const getHighQualityList = async () => {
        let res = await API.getHighQualityListApi()
        if (res.code == 200) {
            highQualityList.value = res.playlists
        } else {
            console.log('获取数据失败');
        }
    }
    const getNewSong = async () => {
        let res = await musicHallApi.getNewSongApi()
        if (res.code == 200) {
            newSongs.value = res.data
            // 取前10条
            newSongs.value = newSongs.value.slice(0, 8)
        } else {
            console.log('获取数据失败');
        }
    }
    // 获取热门电台
    const getHotDj = async () => {
        let res = await musicHallApi.getHotDjApi()
        if (res.code == 200) {
            hotDjLIst.value = res.djRadios
        } else {
            console.log('获取数据失败');
        }
    }
    // 全部新碟
    const getNewAlbum = async (area: string) => {
        let res = await musicHallApi.getNewAlbumApi(area)
        if (res.code == 200) {
            newAlbum.value = res.albums
        } else {
            console.log('获取数据失败');
        }
    }
    return {
        newSongs,
        highQualityList,
        hotDjLIst,
        newAlbum,
        getHighQualityList,
        getNewSong,
        getHotDj,
        getNewAlbum,
    }
})

